// 读取配置文件
// @author Percy

package config

import (
	"gopkg.in/yaml.v2"
	"os"
)

// config 总配置文件
type config struct {
	System   system   `yaml:"system"`
	Database database `yaml:"database"`
	Cert     cert     `yaml:"cert"`
}

// 系统配置
type system struct {
	Host   string `yaml:"host"`
	Port   int    `yaml:"port"`
	Env    string `yaml:"env"`
	Domain string `yaml:"domain"`
}

type database struct {
	DbType  string  `yaml:"dbType"`
	Mongodb mongodb `yaml:"mongodb"`
}

type mongodb struct {
	Uri      string `yaml:"uri"`
	Database string `yaml:"database"`
}
type cert struct {
	PublicKeyPath  string `yaml:"publicKeyPath"`
	PrivateKeyPath string `yaml:"privateKeyPath"`
}

var Cfg *config

// init 初始化配置
func init() {
	yamlFile, err := os.ReadFile("./config.yaml")
	if err != nil {
		panic(err.Error())
		return
	}
	yaml.Unmarshal(yamlFile, &Cfg)
}
